package com.xuzz.study.spring.bean.lifecyle;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;

public class ExampleBeanInstantiationAwareBeanPostProcessorAdapter extends InstantiationAwareBeanPostProcessorAdapter {

    public ExampleBeanInstantiationAwareBeanPostProcessorAdapter(){
        super();
        System.out.println("【ExampleBeanInstantiationAwareBeanPostProcessorAdapter】的构造函数执行");
    }
    @Override
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
        System.out.println("【ExampleBeanInstantiationAwareBeanPostProcessorAdapter】的postProcessProperties设置属性时执行");
        if(bean  instanceof ExampleBean) {
            System.out.println(("【ExampleBeanInstantiationAwareBeanPostProcessorAdapter】postProcessProperties】"+((ExampleBean)bean).info()));
        }
        return super.postProcessProperties(pvs, bean, beanName);
    }

    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        System.out.println("【ExampleBeanInstantiationAwareBeanPostProcessorAdapter】的postProcessBeforeInitialization实例化前执行，此时的beanClass="+beanClass);
        //可以在此处改变此类对象，比如使用代理类
        return super.postProcessBeforeInstantiation(beanClass,beanName);
    }

    @Override
    public boolean postProcessAfterInstantiation(Object bean,  String beanName) throws BeansException {
        System.out.println("【ExampleBeanInstantiationAwareBeanPostProcessorAdapter】的postProcessAfterInitialization实例化后执行，此时的bean="+bean);
        return super.postProcessAfterInstantiation(bean,beanName);
    }
}
